<?php
error_reporting(0);
session_start();
//Written by Slyferz
$page = $_GET["page"];

function sqlConnect()
{
	include 'includes/config.php';
	//setting up the database variables for recruitment and authentication
	//making the database connection
	$db = mysql_connect($snowD->localhost,$snowD->uname,$snowD->pass) or die(mysql_error());
	mysql_select_db($snowD->db,$db) or die(mysql_error());
}
sqlConnect();

//metadata and junk
function top()
{
	echo("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
	<html xmlns=\"http://www.w3.org/1999/xhtml\">
	<head>
	<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />
	<title>hirr Tools</title>
	<link href = './style.css' rel = 'stylesheet' type = 'text/css' />
	</head>");
}
//the page banner
function banner($page)
{
	echo("<div id = 'header' ><img src = 'http://tgrads.com/files/Logo_The_Graduates.png' width = '300' height = '368' alt = 'logo'/></div>");
}
//the bottom of the page
function footer()
{
	echo("<div class = 'bottom'>&copy; The Graduates ".date("Y", (time() - (2*60*60)))."</div>
</body>
</html>");
}
//the pages incorperated into the site
function body($page)
{
	//logging in or out first, because it can get cranky
	if($page == 'login')
	{
		echo("
		<div class = 'middle'>");
		include("login.php");
	}
	else if($page == 'logout')
		include("logout.php");
	else if($page == 'error')
		include("error.php");
	//$result = mysql_query("SELECT access FROM userinfo WHERE userid = '".$_SESSION["userid"]."'");
	//$row = mysql_fetch_array($result);
	//$access = $row[0];
	if(!empty($_SESSION['userid']))
		$userid = $_SESSION['userid'];
	$access = getAcc('recruitment',$userid);
	$overall = getOv($userid);

	if($page != 'error' && $page != 'logout' && $page != 'login')
	{
		echo("
		<div class = 'middle'>");
	}
	if($page == 'apply')
	{
		if(empty($_SESSION["userid"]))
		{
			include("apply.php");
		}
		else if($access > 1)
		{
			include("appAdmin.php");
		}
	}
	else if($page == 'register')
	{
		include("register.php");
	}
	else if($page == 'quest')
	{
		include("questions.php");
	}
	else if($page == 'denied')
	{
		include("denied.php");
	}
	else if($page == 'api')
	{
		include('api2.php');
	}
	else if($page == 'alts')
	{
		include('alts.php');
	}
	else if($page == 'screen')
	{
		include('screen.php');
	}
	else if($page == 'submitted')
	{
		include('submitted.php');
	}
	else if($page == 'setAttribs')
	{
		include('setAttribs.php');
	}
	else if($page == 'calc')
	{
		include("restrictedParse.php");
	}
	else
	{
		$access = getAcc('snowflake',$userid);
		if($page == 'credits' && ($access == 5 || $access == 3))
			include("credits.php");
		else 
		{
			$access = getAcc('recruitment',$userid);
			if($page == 'appedit' && $access == 5)
				include("appEdit.php");
			else if(($page == 'access' && $access == 5) || ($page == 'access' && $overall == 3))
			{
				echo("<table class = 'middle'>");
				include("access.php");
		 		echo("</table>");
			}
			else
			{
				if($page != 'logout' && $page != 'login')
			        echo("
				<div>
				</div>");
			}
		}
	}
	//else echo("Beware, lemmings wander here!");
	if($page != 'error' && $page != 'logout')
	{
		echo("
		</div>
		</div>");
	}
}
//grouping these together for the sake of simplicity
function aboveBody($page)
{
	if($page != 'error' && $page != 'logout')
	{
		top();
		nav($page);
		banner($page);
	}
}
//showing options on the left hand side of the page
function nav($page)
{
	//creating the structure for the body
	echo("
<body>
	<div class = 'body1'>
	<br />
	<div id = 'sidelinks'>
	<div class = 'logo'></div><br />");
	if(!empty($_SESSION["userid"]))
	{
		$userid = $_SESSION["userid"];
		//$result = mysql_query("SELECT access FROM userinfo WHERE userid = '".$userid."'");
		//$row = mysql_fetch_array($result);
		//$access = $row[0];
	}
	//the new authentication system
	include("overall.php");
	include("toolAccess.php");
	$access = getAcc('recruitment',$userid);
	$overall = getOv($userid);
	if($page != 'setAttribs' || $access == 5)
	{
		//show when the user is not logged in
		if(empty($_SESSION["userid"]))
		{
			echo("
			<a href = 'index2.php?page=login'>Login</a>");
		}
		$access = getAcc('recruitment',$userid);
		if($access == 5 || $overall == 3)
		{
			echo("
				<a href = 'index2.php?page=access'>Member Access</a>");
		}
		//else they do not see the admin tab
		else if(empty($access))
		{
			echo("
			<a href = 'index2.php?page=register'>Officer Registration</a>");
		}
		//snowflake
		$access = getAcc('snowflake',$userid);
		if($access > 1)
			echo("<a href = 'index.php'>Snowflake</a>");
		//when the user is logged in, the logout button is shown
		if(!empty($_SESSION["userid"]))
		{
			echo("
			<a href = 'index2.php?page=logout'>Logout</a>");
		}
	}
	echo("	
	</div>");
}
//executing the functions in the desired order
aboveBody($page);
body($page);
footer();
//closing that database connection
mysql_close($db);

?>
